package com.fyz.aaronfjava.common.config;

import com.fyz.aaronfjava.common.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

/**
 * @Author：AaronF
 * @Date：2024/1/30 15:43
 * @description 过滤器配置类
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<MyFilter> myFilter() {
        FilterRegistrationBean<MyFilter> registrationBean = new FilterRegistrationBean<>();
        // 设置过滤器
        registrationBean.setFilter(new MyFilter());
        // 设置过滤的路径
        registrationBean.setUrlPatterns(Collections.singleton("/*"));
        // 当有多个过滤器的时候 order数值越低 过滤器优先级越高
        registrationBean.setOrder(1);
        return registrationBean;
    }

}
